package cn.ilikes.tools.hbase.jpa.query;

import java.util.List;

import javax.persistence.Parameter;
import javax.persistence.Query;

import cn.ilikes.tools.hbase.jpa.persistences.context.AbstractContext;
import cn.ilikes.tools.hbase.jpa.persistences.context.Operation.OperationType;
import cn.ilikes.tools.hbase.jpa.persistences.context.operations.QueryOperation;
import cn.ilikes.tools.hbase.jpa.query.iquerys.JPAQuery;

public class HbaseQueryImpl extends HBaseQuery {

	//	private JPAQuery jpaQuery;

	private AbstractContext abstractContext;

	private QueryOperation queryOperation;

	private void setQueryOperation(QueryOperation queryOperation) {
		this.queryOperation = queryOperation;

	}

	public HbaseQueryImpl(JPAQuery jpaQuery, AbstractContext abstractContext) {
		super();
		this.abstractContext = abstractContext;
		QueryOperation queryOperation = new QueryOperation(OperationType.query, this.abstractContext, jpaQuery);
		setQueryOperation(queryOperation);
	}

	@Override
	public List getResultList() {
		queryOperation.init();
		return (List) abstractContext.operation(queryOperation);

	}

	@Override
	public Object getSingleResult() {
		queryOperation.init();
		return (Object) abstractContext.operation(queryOperation);
	}

	@Override
	public Query setParameter(String arg0, Object arg1) {
		Parameter parameter = new HbaseParameter(arg0, arg1.getClass());
		queryOperation.getJpaQuery().setParameter(parameter, arg1);
		return this;
	}

}
